package com.dhcc.bpm.alarm.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.alarm.entity.AlarmDbInfoConfig;
import com.dhcc.bpm.alarm.mapper.AlarmDbInfoConfigMapper;
import com.dhcc.bpm.alarm.service.IAlarmDbInfoConfigService;
import com.dhcc.bpm.alarm.utils.SQLutil;
import com.dhcc.bpm.alarm.vo.AlarmDbInfoConfigVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Connection;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xiafayu
 * @since 2022-02-16
 */
@Slf4j
@Service
public class AlarmDbInfoConfigServiceImpl extends ServiceImpl<AlarmDbInfoConfigMapper, AlarmDbInfoConfig> implements IAlarmDbInfoConfigService {
    @Autowired
    AlarmDbInfoConfigMapper alarmDbInfoConfigMapper;

    @Override
    public IPage<AlarmDbInfoConfigVO> selectAlarmDbInfoConfigPage(IPage<AlarmDbInfoConfigVO> page, AlarmDbInfoConfigVO AlarmDbInfoConfig) {
        return page.setRecords(alarmDbInfoConfigMapper.selectAlarmDbInfoConfigPage(page, AlarmDbInfoConfig));
    }

    @Override
    public boolean sqlConnection(AlarmDbInfoConfig alarmDbInfoConfig) {
        
        Connection conn = null;
        try {
			conn = SQLutil.getConnection(alarmDbInfoConfig);
			return (null == conn) ? false : true;
		} catch (Exception e) {
			log.info("数据库测试连接异常！");
		} finally {
			SQLutil.release(conn);
		}
        return false;
    }
}
